<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>登录日志查询</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
  <link rel="stylesheet" th:href="@{/adminui/dist/css/admin.css}" media="all">
  <link rel="stylesheet" th:href="@{/style/custom.css}" media="all">
</head>
<body>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto layui-form-pane" lay-filter="LAY-login-log-front-form">
      <div class="layui-form-item">
        <div class="layui-inline">
          <label class="layui-form-label">用户ID</label>
          <div class="layui-input-block">
            <input type="text" name="userId" placeholder="请输入" autocomplete="off" class="layui-input" lay-affix="clear">
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">用户名</label>
          <div class="layui-input-block">
            <input type="text" name="username" placeholder="请输入" autocomplete="off" class="layui-input" lay-affix="clear">
          </div>
        </div>
        <div class="layui-inline">
          <button class="layui-btn layui-btn-normal layui-btn-sm" lay-submit lay-filter="LAY-login-log-front-search">
            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> 搜索
          </button>
          <button class="layui-btn layui-btn-primary layui-btn-sm" lay-submit lay-filter="LAY-login-log-front-reset">
            <i class="layui-icon layui-icon-refresh layuiadmin-button-btn"></i> 重置
          </button>
        </div>
      </div>
    </div>

    <div class="layui-card-body">
      <div class="layui-btn-group" style="padding-bottom: 10px;">
        <!--刷新-->
        <button type="button" class="layui-btn layui-btn-normal btn-op-login-log layui-btn-sm" data-type="refresh">
          <i class="layui-icon">&#xe666;</i>刷新
        </button>
      </div>

      <table id="LAY-login-log-table" lay-filter="LAY-login-log-table"></table>

    </div>
  </div>
</div>

<script th:src="@{/layui/layui.js}"></script>
<script>
  layui.config({
    base: '/'
  }).extend({
    flying: 'flying'
  }).use(['index', 'flying'], function () {
    let $ = layui.$;
    let admin = layui.admin;
    let layer = layui.layer;
    let form = layui.form;
    let table = layui.table;
    let flying = layui.flying;

    //监听搜索
    form.on('submit(LAY-login-log-front-search)', function (data) {
      let param = data.field;
      //执行重载
      table.reload('LAY-login-log-table', {
        where: {param}
      });
    });

    // 监听重置
    form.on('submit(LAY-login-log-front-reset)', function (data) {
      let field = data.field;
      for (let key of Object.keys(field)) {
        field[key] = '';
      }
      form.val("LAY-login-log-front-form", field);
    });

    //事件
    let active = {
      refresh: function () {
        let param = form.val("LAY-login-log-front-form");
        //执行重载 数据刷新
        table.reload('LAY-login-log-table', {
          where: {param}
        });
      }
    };

    //执行事件操作
    $('.layui-btn.btn-op-login-log').on('click', function () {
      let type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });

    flying.table({
      elem: '#LAY-login-log-table',
      url: '/system/login/log/page', //数据接口
      cols: [
        {type: 'numbers', fixed: 'left', title: '序号'}
        , {field: 'userId', title: '用户ID', minWidth: 100}
        , {field: 'userName', title: '用户名', minWidth: 100}
        , {field: 'name', title: '姓名', minWidth: 100}
        , {field: 'happenType', title: '发生类型', minWidth: 80, templet: function (d) {
            if (d.happenType == '用户登录') {
              return '<span class="layui-bg-green layui-badge-rim">用户登录</span>';
            } else if (d.happenType == '用户注销') {
              return '<span class="layui-bg-blue layui-badge-rim">用户注销</span>';
            }  else {
              return '<span class="layui-bg-orange layui-badge-rim">会话失效</span>';
            }
          }, unresize: true}
        , {field: 'happenIp', title: '访问IP', minWidth: 100}
        , {field: 'remark', title: '备注描述', minWidth: 100}
        , {field: 'happenTime', title: '发生时间', templet: '<div>{{ layui.util.toDateString(d.happenTime, "yyyy-MM-dd HH:mm:ss") }}</div>', minWidth: 200}
      ]
    });

  });

</script>
</body>
</html>
